using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace SaleManagement.Entity.Mapping
{
    public class OrderMap : EntityTypeConfiguration<Order>
    {
        public OrderMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.OrderNumber)
                .IsRequired()
                .IsFixedLength()
                .HasMaxLength(20);

            // Table & Column Mappings
            this.ToTable("Order");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.OrderNumber).HasColumnName("OrderNumber");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.CustomerId).HasColumnName("CustomerId");
            this.Property(t => t.Status).HasColumnName("Status");
            this.Property(t => t.ShipId).HasColumnName("ShipId");

            // Relationships
            this.HasRequired(t => t.Customer)
                .WithMany(t => t.Orders)
                .HasForeignKey(d => d.CustomerId);
            this.HasOptional(t => t.Ship)
                .WithMany(t => t.Orders)
                .HasForeignKey(d => d.ShipId);

        }
    }
}
